package xyz.zhouzhousag.server.controller;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;
import xyz.zhouzhousag.server.pojo.entity.AdminUserRoleRel;
import xyz.zhouzhousag.server.pojo.entity.BaseResponse;
import xyz.zhouzhousag.server.service.AdminUserRoleRelService;

import javax.annotation.Resource;

/**
 * 角色用户关系表(AdminUserRoleRel)表控制层
 *
 * @author Yin.Liu8
 * @since 2021-09-26 16:21:05
 */
@RestController
@RequestMapping("adminUserRoleRel")
public class AdminUserRoleRelController {
    /**
     * 服务对象
     */
    @Resource
    private AdminUserRoleRelService adminUserRoleRelService;

    /**
     * 分页查询
     *
     * @param adminUserRoleRel 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public BaseResponse<Page<AdminUserRoleRel>> queryByPage(AdminUserRoleRel adminUserRoleRel, PageRequest pageRequest) {
        return BaseResponse.success(this.adminUserRoleRelService.queryByPage(adminUserRoleRel, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public BaseResponse<AdminUserRoleRel> queryById(@PathVariable("id") Integer id) {
        return BaseResponse.success(this.adminUserRoleRelService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param adminUserRoleRel 实体
     * @return 新增结果
     */
    @PostMapping
    public BaseResponse<AdminUserRoleRel> add(AdminUserRoleRel adminUserRoleRel) {
        return BaseResponse.success(this.adminUserRoleRelService.insert(adminUserRoleRel));
    }

    /**
     * 编辑数据
     *
     * @param adminUserRoleRel 实体
     * @return 编辑结果
     */
    @PutMapping
    public BaseResponse<AdminUserRoleRel> edit(AdminUserRoleRel adminUserRoleRel) {
        return BaseResponse.success(this.adminUserRoleRelService.update(adminUserRoleRel));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public BaseResponse<Boolean> deleteById(Integer id) {
        return BaseResponse.success(this.adminUserRoleRelService.deleteById(id));
    }

}

